package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"warehouse/models"
)

type WareHouseController struct {
	beego.Controller
}

func (c *WareHouseController) Add() {

	types := c.GetString("types")
	name := c.GetString("name")
	address := c.GetString("address")
	var ware = models.Warehouse{
		Types:   types,
		Name:    name,
		Address: address,
	}

	if address == "" {
		c.Data["json"] = models.JsonR{
			Code: 500,
			Msg:  "仓库地址不能为空",
			Data: nil,
		}
		c.ServeJSON()
		return
	}

	err := models.DB.Model(&models.Warehouse{}).Create(&ware).Error
	if err != nil {
		c.Data["json"] = models.JsonR{
			Code: 500,
			Msg:  "添加失败",
			Data: nil,
		}
		c.ServeJSON()
		return
	}
	c.Data["json"] = models.JsonR{
		Code: 200,
		Msg:  "添加成功",
		Data: nil,
	}
	c.ServeJSON()
}
